package controller;

import entity.Device;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.DeviceService;
import entity.Result;

/**
 * @program: IoT201759225309
 * @description: Device控制层
 * @author: Xiaozhuoer
 * @create: 2021-06-06 11:27
 **/
@Controller
@RequestMapping("device")
public class DeviceController {

    private final DeviceService deviceService;

    public DeviceController(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    /**
     * 添加Device
     * @param device
     * @return Result
     */
    @RequestMapping("/addDevice")
    @ResponseBody
    public Result addDevice(Device device){
        Result result = new Result();
        deviceService.addDevice(device);
        result.setStatus(0);
        return result;
    }
    /**
     * 查询所有Device
     * @return Result
     */
    @RequestMapping("/findAll")
    @ResponseBody
    public Result findAll(){
        Result result = new Result();
        result.setData(deviceService.findAll());
        return result;
    }
    /**
     * 根据DeviceId修改Device信息
     * @param id,device
     * @return Result
     */
    @RequestMapping("/modifyDevice")
    @ResponseBody
    public Result modifyDevice(String id,Device device){
        Result result = new Result();
        deviceService.modifyDevice(id,device);
        return result;
    }
    /**
     * 根据DeviceId删除Device
     * @param id
     * @return Result
     */
    @RequestMapping("/deleteDevice")
    @ResponseBody
    public Result deleteDevice(String id){
        Result result = new Result();
        deviceService.deleteDevice(id);
        return result;
    }
    /**
     * 添加Device信息
     * @param device
     * @return Result
     */
    @RequestMapping("/addDeviceValue")
    @ResponseBody
    public Result addDeviceValue(Device device){
        Result result = new Result();
        deviceService.addDeviceValue(device);
        result.setStatus(0);
        return result;
    }
    /**
     * 通过DeviceName查找Device
     * @param devicename
     * @return Result
     */
    @RequestMapping("/findOneInDeviceName")
    @ResponseBody
    public Result findOneInDeviceName(String devicename){
        Result result = new Result();
        result.setData(deviceService.findOneInDeviceName(devicename));
        result.setStatus(0);
        return result;
    }
    /**
     * 通过idStr删除DeviceValue
     * @param idStr
     * @return Result
     */
    @RequestMapping("/deleteValue")
    @ResponseBody
    public Result deleteValue(String idStr){
        Result result = new Result();
        deviceService.deleteValue(idStr);
        result.setStatus(0);
        return result;
    }
}
